package com.ruoyi.web.controller.config;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.HingeInstallation;
import com.ruoyi.system.service.HingeInstallationService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 关键装置和重点部位(HingeInstallation)表控制层
 * @since 2023-03-20 17:42:52
 */
@RestController
@RequestMapping("hingeInstallation")
public class HingeInstallationController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private HingeInstallationService hingeInstallationService;

    @GetMapping("/list")
    public TableDataInfo queryByPage(HingeInstallation hingeInstallation) {
        startPage();
        List<HingeInstallation> list = hingeInstallationService.queryAll(hingeInstallation);
        return getDataTable(list);
    }

    /**
     * 分页查询
     *
     * @param hingeInstallation 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<HingeInstallation>> queryByPage(HingeInstallation hingeInstallation, PageRequest pageRequest) {
        return ResponseEntity.ok(this.hingeInstallationService.queryByPage(hingeInstallation, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<HingeInstallation> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.hingeInstallationService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param hingeInstallation 实体
     * @return 新增结果
     */
    @PostMapping("add")
    @PreAuthorize("@ss.hasPermi('hingeInstallation:add')")
    public ResponseEntity<HingeInstallation> add(@Validated @RequestBody HingeInstallation hingeInstallation) {
        return ResponseEntity.ok(this.hingeInstallationService.insert(hingeInstallation));
    }

    /**
     * 编辑数据
     *
     * @param hingeInstallation 实体
     * @return 编辑结果
     */
    @PutMapping("edit")
    @PreAuthorize("@ss.hasPermi('hingeInstallation:edit')")
    public ResponseEntity<HingeInstallation> edit(@Validated @RequestBody HingeInstallation hingeInstallation) {
        return ResponseEntity.ok(this.hingeInstallationService.update(hingeInstallation));
    }

    /**
     * 删除数据
     *
     * @param hingeInstallation 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    @PreAuthorize("@ss.hasPermi('hingeInstallation:delete')")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody HingeInstallation hingeInstallation) {
        return ResponseEntity.ok(this.hingeInstallationService.deleteById(hingeInstallation.getId()));
    }

}

